package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.BondingFamilyDto;
import com.zzyl.nursing.dto.QueryDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.service.impl.DeviceServiceImpl;
import com.zzyl.nursing.domain.HealthDataResult;
import com.zzyl.nursing.vo.InquiryFamilyVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.ViewFamilyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private DeviceServiceImpl deviceService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }
    /**
     * 查看家人列表分页查询
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询")
    public R<List<ViewFamilyVo>> listByPage() {
        return R.ok(familyMemberService.listByPage());
    }

    /**
     *绑定家人
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody BondingFamilyDto dto) {
        int i = familyMemberService.insertFamilyMemberadd(dto);
        if (i < 1) {
            return error("绑定失败");
        }
        return success();
    }
    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<InquiryFamilyVo>> my() {
        return R.ok(familyMemberService.my());
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult queryDevicePropertyStatus(DeviceDto dto){
        String productKey = dto.getProductKey();
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data = deviceService.searchInfo(productKey);
        return success(data);
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<HealthDataResult>> queryDeviceDataListByDay(@RequestBody QueryDto dto){
        List<HealthDataResult> list= deviceService.queryDeviceDataListByDay(dto);
        return R.ok(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<HealthDataResult>> queryDeviceDataListByWeek(@RequestBody QueryDto dto){
        List<HealthDataResult> list= deviceService.queryDeviceDataListByDay(dto);
        return R.ok(list);
    }
}
